**
**  Political Economy of Consumer Debt Relief
**
**  Code for District-level Analysis
**
**  July 2024
**  

clear all
cd  "/Users/zas/Library/CloudStorage/Dropbox/Vote Buying_shared/Georgia/!REStat/Replication"
use "districts.dta"

ssc install binscatter
ssc install outreg2

* Dependent Variables

xtset district_no term

foreach v in zura vasha {
gen `v'_gr = (`v'-l1.`v')/l1.`v'
gen `v'_turn = `v' / Participant
}

label var zura_gr    "Zura growth"
label var vasha_gr   "Vasha growth"

* Independent Variables: Debt relief

foreach v in loans_no id_no debt_tot id_no_w debt_tot_w {
gen `v'_ln = log(`v')
}

label var id_no_ln    "log affected individuals"
label var debt_tot_ln "log cancelled debt"

replace debt_tot = debt_tot / 1000000000
replace debt_tot_w = debt_tot_w / 1000000000
label var debt_tot "debt in billions"
binscatter zura_gr debt_tot , genxq(debt_median_dummy) nq(2) line(connect)
label var debt_median_dummy  "Dummy for median of debt"

* Independent Variables: Controls etc.

foreach v in Participant Voter Turnout{
gen `v'_gr = (`v'-l1.`v')/l1.`v'
gen `v'_ln = log(`v')
gen     `v'_1_ln = `v'_ln     if term==1
replace `v'_1_ln = l1.`v'_1_ln if term==2
}

label var Voter_1_ln        "log registered voters"
label var Participant_1_ln  "log individuals voted"
label var Participant_gr    "Turnout growth"

gen other =  log(cand1 + cand2 +cand4 +cand10+ cand13+ cand17 +cand18+ cand21+ cand22+ cand23+ cand25+ cand27+ cand28+ cand30+ cand31+ cand35+ cand36+ cand40+ cand49+ cand51+ cand58 +cand62 +cand65)
label var other  "log votes for all other candidates in round i"

**
** Save treatment intensity data

preserve
drop if  term==1
keep district_no debt_tot_ln id_no_ln
foreach v in  debt_tot_ln id_no_ln  {
rename `v' d_`v'
}
save "auxiliary_data/treatment_intensity_districts.dta", replace
restore

***
*** Raw Correlations

** Figure 1 (correlations in raw and residualized data)

twoway scatter zura_gr debt_tot_ln [w= Voter], msymbol(circle_hollow)  || lfit  zura_gr debt_tot_ln, scheme(s2mono) ytitle("Growth in GD votes between first and second round") xtitle("Log debt") ylabel(0(.5)1.5) legend(off)
graph export "results/raw_scatter_debt.pdf", as(pdf) replace

reg zura_gr debt_tot_ln Voter_1_ln Turnout_1_ln  if term==2
predict aa
twoway scatter aa debt_tot_ln  || lfit aa debt_tot_ln, scheme(s2mono) ytitle("Growth in GD votes between first and second round") xtitle("Log debt") ylabel(0(.5)1.5) legend(off)
graph export "results/raw_scatter_debt_e.pdf", as(pdf) replace

** Figure C2 Appendix (figure 1 but for log individuals)

twoway scatter zura_gr id_no_ln [w= Voter], msymbol(circle_hollow)  || lfit zura_gr id_no_ln, scheme(s2mono) ytitle("Growth in GD votes between first and second round") xtitle("Log individuals") ylabel(0(.5)1.5) legend(off)
graph export "results/raw_scatter_individuals.pdf", as(pdf) replace

reg zura_gr id_no_ln Voter_1_ln Turnout_1_ln  if term==2
predict bb
twoway scatter bb id_no_ln || lfit bb id_no_ln, scheme(s2mono) ytitle("Growth in GD votes between first and second round") xtitle("Log individuals") ylabel(0(.5)1.5) legend(off)
graph export "results/raw_scatter_individual_e.pdf", as(pdf) replace

***
*** Baseline Results

local controls1 Voter_1_ln Turnout_1_ln

** TABLE 1

foreach y in zura_gr vasha_gr Participant_gr{
foreach x in  debt_tot_ln debt_tot{
reg `y' `x' `controls1' if term==2
outreg2 using results/dist_base, label e(F) ctitle() tex(frag) dec(3) excel drop() sortvar(debt_tot_ln id_no_ln debt_tot debt_median_dummy debt_tot_est id_no_est  Voter_1_ln Participant_1_ln ) append
sum `y' if e(sample)==1
}
}

***
*** Dynamic Results

preserve 

* Prepare data and merge with data on other elections

gen year=2018 if term==1
replace year=2019 if term==2
gen unm 	= vasha_turn *100
gen gd 		= zura_turn *100
gen turnout	= Participant

merge m:m district_no year using "auxiliary_data/past_elections_districts.dta"

* Define variables over time

xtset district_no year

foreach x in  debt_tot_ln id_no_ln  {
bysort district_no: egen `x'a = mean(`x')
drop `x'
rename `x'a `x'
}

gen     el=1 if year==2012
replace el=2 if year==2013
replace el=3 if year==2016
replace el=4 if year==2018
replace el=5 if year==2019
replace el=6 if year==2020

xtset district_no el
foreach v in gd unm{
gen `v'_gr = (`v'-l1.`v')/l1.`v'
}

binscatter gd_gr debt_tot_ln if el==2, genxq(debt2g) nq(2) line(connect) by(year)
binscatter gd_gr debt_tot_ln if el==2, genxq(debt5g) nq(5) line(connect) by(year)

** Figure 2 Panel A (Baseline)

gen ln_turnout = log(turnout)
local control_turnout ln_turnout 

qui bysort district_no (debt2g): replace debt2g=debt2g[1]
reg gd_gr i.debt2g##ib(4).el `control_turnout' if el>2
coefplot, vertical drop(_cons) ytitle("Growth in GD votes in high vs low intesnity districts") keep(2.debt2g#1.el 2.debt2g#2.el 2.debt2g#3.el 2.debt2g#4.el 2.debt2g#5.el 2.debt2g#6.el) yline(0)  baselevels omitted coeflabels(2.debt2g#1.el = 2012 2.debt2g#2.el = 2013 2.debt2g#3.el = 2016 2.debt2g#4.el = 2018(i) 2.debt2g#5.el = 2018(ii) 2.debt2g#6.el = 2020, wrap(20) notick labcolor() labsize(medlarge) labgap()) scheme(s2mono)
graph export "results/Trends_dist_median_growth.pdf", as(pdf) replace

** Figure C2 Panel A (Appendix)

qui bysort district_no (debt5g): replace debt5g=debt5g[1]
gen sample = 1 if debt5g==1 | debt5g==5 
reg gd_gr i.debt5g##ib(4).el `control_turnout' if el>2 & sample==1
coefplot, vertical drop(_cons) ytitle("Growth in GD votes in high vs low intesnity districts") keep(5.debt5g#1.el 5.debt5g#2.el 5.debt5g#3.el 5.debt5g#4.el 5.debt5g#5.el 5.debt5g#6.el) yline(0)  baselevels omitted coeflabels(5.debt5g#1.el = 2012 5.debt5g#2.el = 2013 5.debt5g#3.el = 2016 5.debt5g#4.el = 2018(i) 5.debt5g#5.el = 2018(ii) 5.debt5g#6.el = 2020, wrap(20) notick labcolor() labsize(medlarge) labgap()) scheme(s2mono)
graph export "results/Trends_dist_quint_growth.pdf", as(pdf) replace

restore


***
*** Appendix Robustness Results


** Table C1 Panel A (Results with Individuals)

foreach y in zura_gr vasha_gr Participant_gr{
foreach x in id_no_ln{
* foreach x in  debt_tot_ln id_no_ln debt_median_dummy debt_tot{
reg `y' `x' `controls1' if term==2
outreg2 using results/dist_c1, label e(F) ctitle() tex(frag) dec(3) excel drop() sortvar(debt_tot_ln id_no_ln debt_tot debt_median_dummy debt_tot_est id_no_est  Voter_1_ln Participant_1_ln ) append
sum `y' if e(sample)==1
}
}

** Table C2 (Results for Data Aggregated with Sample Weights Based on Migration Probabilities)

foreach y in zura_gr vasha_gr Participant_gr{	
foreach x in  debt_tot_w_ln id_no_w_ln debt_tot_w{
reg `y' `x' `controls1' if term==2
outreg2 using results/dist_c3, label e(F) ctitle() tex(frag) dec(3) excel drop() sortvar(debt_tot_ln id_no_ln debt_tot debt_tot_w_ln id_no_w_ln debt_tot_w Voter_1_ln Participant_1_ln ) append
}
}

** Table C4 Columns 1-3 (Treatment Effects by Low-vs-High Debt Intensity)

*local controls0
local controls3 Turnout_1_ln

*foreach i in 0 3 1{
foreach y in zura_gr vasha_gr Participant_gr{
foreach x in  debt_median_dummy{
reg `y' `x' `controls3' if term==2
*reg `y' `x' `controls`i'' if term==2
outreg2 using results/dist_c4, label e(F) ctitle() tex(frag) dec(3) excel drop() sortvar(debt_tot_ln id_no_ln debt_tot debt_median_dummy debt_tot_est id_no_est  Voter_1_ln Participant_1_ln ) append
}
}
*}

** Table C5 Panel A (Treatment Effects Controlling for Other Candidates Votes)

local controls2 Voter_1_ln Turnout_1_ln other

foreach y in zura_gr vasha_gr Participant_gr{
foreach x in  debt_tot_ln id_no_ln debt_tot{
reg `y' `x' `controls2' if term==2
outreg2 using results/dist_c5, label e(F) ctitle() tex(frag) dec(3) excel drop() sortvar(debt_tot_ln id_no_ln debt_tot debt_median_dummy debt_tot_est id_no_est  Voter_1_ln Participant_1_ln ) append
}
}

***
*** Appendix Nightlight Results

preserve

* Prepare data and merge with data on night time lights

drop if  term==1
merge m:m district_no using "auxiliary_data/nighttime"

gen y_m = year*100 + month 
xtset district_no y_m

foreach v in mean {
replace `v'=. if `v' ==0
gen `v'_gr = (`v' - `v'[_n-12] ) / `v'[_n-12]
}

** Figure C1 (The Treatment Effects on Average Growth in Monthly Night-Light Luminosity Over Time)

foreach v in mean {
binscatter `v'_gr debt_tot_ln if year>=2018 & year<=2020, genxq(debt2) nq(2) line(connect) by()
reg `v'_gr i.debt2##ib(201809).y_m
coefplot, vertical drop(_cons) keep(2.debt2#*.y_m) yline(0) xline(10.5) baselevels omitted coeflabels(2.debt2#201801.y_m = 2018-Jan 2.debt2#201802.y_m = Feb 2.debt2#201803.y_m = Mar 2.debt2#201804.y_m = Apr 2.debt2#201805.y_m = May 2.debt2#201806.y_m = Jun 2.debt2#201807.y_m = Jul 2.debt2#201808.y_m = Aug 2.debt2#201809.y_m = Sep 2.debt2#201810.y_m = Oct 2.debt2#201811.y_m = Nov 2.debt2#201812.y_m = Dec   2.debt2#201901.y_m = 2019-Jan 2.debt2#201902.y_m = Feb 2.debt2#201903.y_m = Mar 2.debt2#201904.y_m = Apr 2.debt2#201905.y_m = May 2.debt2#201906.y_m = Jun 2.debt2#201907.y_m = Jul 2.debt2#201908.y_m = Aug 2.debt2#201909.y_m = Sep 2.debt2#201910.y_m = Oct 2.debt2#201911.y_m = Nov 2.debt2#201912.y_m = Dec   2.debt2#202001.y_m = 2020-Jan 2.debt2#202002.y_m = Feb 2.debt2#202003.y_m = Mar 2.debt2#202004.y_m = Apr 2.debt2#202005.y_m = May 2.debt2#202006.y_m = Jun 2.debt2#202007.y_m = Jul 2.debt2#202008.y_m = Aug 2.debt2#202009.y_m = Sep 2.debt2#202010.y_m = Oct 2.debt2#202011.y_m = Nov 2.debt2#202012.y_m = Dec , wrap(20) notick labcolor() angle(90) labsize(small) labgap()) scheme(s2mono)
graph export "results/nightlight_`v'.pdf", as(pdf) replace
drop debt2
}

** Table C6 and Figure C3 (The Treatment Effect in Poor and Rich Districts)

foreach y in zura_gr vasha_gr{
foreach v in mean {
reg `y' c.debt_tot_ln##c.`v' if year==2018 & month==10
gen `v'_sample=`v' if e(sample)==1
outreg2 using results/night_c6, label e(F) ctitle() tex(frag) dec(3) excel drop() sortvar(debt_tot_ln id_no_ln debt_tot_est id_no_est  Voter_1_ln Participant_1_ln ) append
margins, dydx(debt_tot_ln) at(`v'=(0(5)35))
marginsplot, yline(0) graphregion(color(white)) legend(off) title("") xtitle(Night Light Intensity) legend() addplot(hist `v'_sample, mcolor(gs12%50) below yaxis(2) yscale(range(0(.2)1) alt axis(2))) scheme(s2mono)
graph export "results/night_`y'.pdf", as(pdf) replace
drop `v'_sample
}
}

restore
